#include"list.h"


STnode* Buynode(Datatype x)
{
	STnode* newnode = (STnode*)malloc(sizeof(STnode));
	if (newnode == NULL)
	{
		perror("malloc fail");
		return NULL;
	}
	newnode->data = x;
	newnode->prev = NULL;
	newnode->next = NULL;
	return newnode;
}
STnode* STinit()
{
	STnode* phead = Buynode(-1);
	phead->prev = phead;
	phead->next = phead;
	return phead;
}
void STPrint(STnode* phead)
{
	STnode* cur = phead->next;
	while (cur!=phead)
	{
		printf("%d->", cur->data);
		cur = cur->next;
	}
	printf("\n");
}

void Pushfront(STnode* phead, Datatype x)
{
	assert(phead);
	STnode* newnode = Buynode(x);

	newnode->next = phead->next;
	phead->next->prev = newnode;
	phead->next = newnode;
	newnode->prev = phead;

}

void Pushback(STnode* phead, Datatype x)
{
	STnode* newnode = Buynode(x);

	STnode* tail = phead->prev;

	tail->next = newnode;
	newnode->prev = tail;
	phead->prev = newnode;
	newnode->next = phead;


}
